const path = require('path')

const baseUrl = src => path.join(__dirname, src)

module.exports = {
  lintOnSave: false,
  chainWebpack: config => {
    config.resolve.alias
      .set('@', baseUrl('./src'))
      .set('_c', baseUrl('./src/components'))
    config.when(process.env.NODE_ENV === 'production', c => {
      c.entry('app').clear().add('./src/main-pro.js')
      config.set('externals', {
        vue: 'Vue',
        'router': 'VueRouter',
        axios: 'axios',
        vuex: 'Vuex',
        lodash: '_'
      })
    })
    config.when(process.env.NODE_ENV === 'development', config => {
      config.entry('app').clear().add('./src/main.js')
      config.plugin('html').tap(args => {
        args[0].isProd = false
        return args
      })
    })
  },
  productionSourceMap: false,
  devServer: {
    proxy: {
      '/elm': {
        target: 'https://shadow.elemecdn.com',
        secure: false,
        pathRewrite: { '^/elm': '' }
      },
      '/act': {
        target: 'https://activity.m.duiba.com.cn/chw/visual-editor',
        secure: false,
        pathRewrite: { '^/act': '' }
      },
      '/base': {
        target: 'https://h5.ele.me',
        secure: false,
        pathRewrite: { '^/base': '' }
      },
      '/help': {
        target: 'https://help.ele.me',
        secure: false,
        pathRewrite: { '^/help': '' }
      },
      '/shop': {
        target: 'https://shopping.ele.me',
        secure: false,
        pathRewrite: { '^/shop': '' }
      }
    },
    host: 'localhost',
    port: 8080
  },
  css: {
    loaderOptions: {
      css: {},
      postcss: {
        plugins: [
          require('postcss-px2rem')({
            remunit: 37.5
          })
        ]
      }
    }
  }
}
